所以,我想知道如何从谷歌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