我有一个代码可以在instagram链接的URL中搜索,即使我可以在URL的源代码中手动找到,也不会返回一些URL。该URL没有被阻止,因为我可以在相同的URL中找到Facebook链接,但在instagram的URL中找不到。
import re
import requests
try:
url = "https://www.walmart.com.br"
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
page = requests.get(url, headers = headers)
page = page.text
instagram_link = re.findall('https?://www.instagram.com/(?:[-\w.]|(?:%[\da-fA-F]{2}))+', page)[0]
print("Instagram:", instagram_link)
except:
pass
instagram_link = "Not found"
print("Instagram:", instagram_link)
try:
facebook_link = re.findall('https?://www.facebook.com/(?:[-\w.]|(?:%[\da-fA-F]{2}))+', page)[0]
print("Facebook:", facebook_link)
except:
pass
facebook_link = "Not found"
print("Facebook:", facebook_link)
>>> Instagram: Not found
>>> Facebook: https://www.facebook.com/walmart.com
答案 0 :(得分:2)
instagram_link = re.findall('https?://www.instagram.com/(?:[-\w.]|(?:%[\da-fA-F]{2}))+', page)[0]
您在Instagram网址中忘记了www