【发布时间】:2019-08-03 19:36:15
【问题描述】:
我创建了一个链接列表,这些链接连接到 LinkedIn 的页面。这些链接是使用 LinkedIn 的招聘功能(在付费墙后面)汇总的。当我将链接粘贴到浏览器中并检查 html 代码时,它看起来很标准,并且我能够轻松识别我正在搜索的元素(见下文)。
但是,当我运行我的 python 代码并使用漂亮的汤来获取 HTML 时,返回的 HTML 看起来与浏览器的检查元素视图中的外观完全不同。而不是普通的标签,HTML 充满了变量,基本上看起来不像我以前见过的任何东西(还没有做大量的抓取)。
是否有可能获得看起来像我在浏览器上看到的 HTML,而不是看起来很疯狂的东西?这些链接是使用 recuriter 搜索功能编译的,所以我想我以某种方式使用搜索变量而不是实际结果来提取 html,但我真的不知道。
这是我用来创建 html 文件的代码。我希望最后一行提取我正在寻找的数据,假设我可以获得正确的 html。
#Used to create file
with open('departures.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
browser.get(row['link'])
page = BeautifulSoup(browser.page_source, 'lxml')
html = page.prettify()
with open("output1.html", "w") as file:
file.write(unicode(html))
#Code I want to Run right now it just returns an empty list
position = page.find_all('span', class_= 'keyword')
当我使用浏览器转到链接时,我试图找到的 HTML:
<span class="keyword"> Account Manager</span>
Small Piece of Actual HTML returned: <code id="profile-data" style="display: none;">
<!--{"breadcrumbs":{"customSearchURL":"/recruiter/smartsearch? updateSearchHistory=false&decorateHits=true&decorateFacets=false&doFacetCounting=true&searchHistoryId=3392867616&resetFacets=false&searchCacheKey=f4b1a865-50e8-4f59-ba48-9dff595e63e5%2CoUbi&searchRequestId=4d25da0f-1f73-4722-8586-9652b3f98b97%2CQSZO&doResultCaching=false&forceResultFromCache=false&origin=PPSL&doProjectBasedCounting=false&count=25&start=700","linkContext":"Controller:smartSearch,Action:search,ID:3392867616","context":
【问题讨论】:
标签: python beautifulsoup