所以,我想知道如何從谷歌URL抓取。像紫色超鏈接一樣,我將如何獲得該URL?Python硒超鏈接
我知道你可以刮的超級鏈接下面的網址,但有時他們看起來是這樣。正如你可以看到它不是一個完整的URL。
我已經試過..
posts2 = driver.find_elements_by_class_name("_Rm")
for post2 in posts2:
print(post2.text)
driver.get("https://www.google.com/#q=" + user_input)
for n in range(20):
try:
driver.find_element_by_xpath("//*[@id='pnnext']/span[2]").click()
except:
pass
time.sleep(2)
posts2 = driver.find_elements_by_tag_name("a")
for post2 in posts2:
print(post2.get_attribute("href"))
text_file.write(post2.get_attribute + "\n")
Traceback (most recent call last):
File "C:/Users/Josh/PycharmProjects/untitled/Testing.py", line 28, in <module>
text_file.write(post2.get_attribute + "\n")
TypeError: unsupported operand type(s) for +: 'method' and 'str'
https://www.google.com/setprefs?suggon=2&prev=https://www.google.com/&sig=0_ywwzcI8qNScukbiTaRoKlRiERJY%3D
'link'沒有顯示全'url'。它將'url'作爲'href'參數保存在html標籤中。 – furas
好吧,那麼無論如何,我可以使用Selenium獲取該信息? – Skid
嘗試'post2.argument('href')' – furas