The import time
Driver=webdriver. Firefox (executable_path=r 'C: \ Users \ \ Administrator \ Desktop \ geany \ geckodriver exe')
Driver. The get (" https://zh.airbnb.com/s/Shenzhen - China/homes ") find all rental housing in the page #
Rent_list=driver. Find_elements_by_css_selector (' div. _gigle7 ')
For eachhouse rent_list in:
Try:
Comment=eachhouse. Find_element_by_css_selector (' span. _lcy09umr ')
Comment=the comment. The text
Except:
Comment=0
Price=eachhouse. Find_element_by_css_selector (' div. _lyarz4r ')
Price=price. Text. Replace (" night ", ""). The replace (" price", ""). The replace (" \ n", "")
Name=eachhouse. Find_element_by_css_selector (' div. _vbshb6 ')
Name=name. Text
The details.=eachhouse find_element_by_css_selector (' span. _14ksqu3j)
The details=the text
House_type=the split (". "[0])
Bed_number=the split (". "[1])
Print (comment, price, name, house_type, bed_number)
CodePudding user response:
Specific situation is not very clear, but see you upload code is no indentation, could it be indented,CodePudding user response:
Searched under the div, with 22 matching, this position may be right, with unique value like id ah, good looking for some, this method is not ripe, xpath is familiar with a little, try debug output
CodePudding user response:
No error output and empty,Find_element_by_css_selector haven't find